package problem435;

import java.util.Arrays;

//435.无重叠区间
//https://leetcode.cn/problems/non-overlapping-intervals/

class Solution {
    public int eraseOverlapIntervals(int[][] intervals) {
        Arrays.sort(intervals,(a, b)->{
            return a[0] - b[0];
        });
        int ret  = 0;
        int n = intervals.length;
        int left = intervals[0][0], right = intervals[0][1];
        for(int i = 1; i<n; i++) {
            if(intervals[i][0] < right) {
                ret ++;
                right = Math.min(right, intervals[i][1]);
            }else {
                right = intervals[i][1];
            }
        }
        return ret;
    }
}
